package 牛客.排序;
//给定一个数组，请你编写一个函数，返回该数组排序后的形式。

public class Sort {
    public void QuickSort(int[] a, int start, int end){
        if(start < end) {
            int i = start, j = end;
            while (i < j) {
                while (i < j && a[i] <= a[j]) j--;
                if (i < j) {
                    int t = a[i];
                     a[i] = a[j];
                     a[j] = t;
                    i++;
                }
                while (i < j && a[i] <= a[j]) i++;
                if (i < j) {
                    int t = a[i];
                    a[i] = a[j];
                    a[j] = t;
                    j--;
                }
            }
            //此时i=j
            QuickSort(a, start, i - 1);
            QuickSort(a, i + 1, end);
        }
    }
    public static void main(String[] args) {
        Sort obj = new Sort();
        int[] a = {2,5,32,6,8,17,39,25};
        obj.QuickSort(a, 0,a.length - 1);
        for (Integer i: a)
            System.out.print(i + " ");
    }

}
